package com.example.tms.controller;

import com.example.tms.bean.*;
import com.example.tms.mapper.*;
import com.example.tms.tools.GlobalParam;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.*;

import javax.persistence.criteria.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import com.example.tms.annotation.*;

/**
 * 订单管理
 */
@RestController
public class OrderController {

    private final OrderMapper orderMapper;
    private final RoadVMapper roadVMapper;
    private final RoadMapper roadMapper;
    private final CstmrMapper cstmrMapper;
    private final AreaMapper areaMapper;
    private final WaybillMapper waybillMapper;
    private final OilPriceMapper oilPriceMapper;
//    private final CycleMapper cycleMapper;

    @Autowired
    public OrderController(OrderMapper orderMapper, RoadVMapper roadVMapper, RoadMapper roadMapper, CstmrMapper cstmrMapper, AreaMapper areaMapper, WaybillMapper waybillMapper, OilPriceMapper oilPriceMapper) {
        this.orderMapper = orderMapper;
        this.roadVMapper = roadVMapper;
        this.roadMapper = roadMapper;
        this.cstmrMapper = cstmrMapper;
        this.areaMapper = areaMapper;
        this.waybillMapper = waybillMapper;
//       this.cycleMapper = cycleMapper;
        this.oilPriceMapper = oilPriceMapper;
    }

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    //查询订单信息列表
    @RequiresPermissions("211")
    @RequestMapping(value = "order",method = RequestMethod.GET)
    public ReturnInfo getOrderList(@RequestParam(value = "pageNum", defaultValue = "1") String pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") String pageSize,
                                   @RequestParam(required = false, defaultValue = "") String khjc,
                                   @RequestParam(required = false, defaultValue = "") String khzjm,
                                   @RequestParam(required = false, defaultValue = "") String xlmc,
                                   @RequestParam(required = false, defaultValue = "") String xlzjm,
                                   @RequestParam(required = false, defaultValue = "") String qymc,
                                   @RequestParam(required = false, defaultValue = "") String qyzjm,
                                   @RequestParam(required = false, defaultValue = "") String ddh,
                                   @RequestParam(required = false, defaultValue = "") String ddzt,
                                   @RequestParam(required = false, defaultValue = "") String qsrq,
                                   @RequestParam(required = false, defaultValue = "") String jsrq,
                                   @RequestParam(required = false, defaultValue = "") String xq,
                                   @RequestParam(required = false, defaultValue = "") String ddlx){

            Specification<OrderMgmt> specification = new Specification<OrderMgmt>() {
                /**
                 * 构造断言
                 *
                 * @param root    实体对象引用
                 * @param //query 规则查询对象
                 * @param //cb    规则构建对象
                 * @return 断言
                 */
                @Override
                public Predicate toPredicate(Root<OrderMgmt> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                    List<Predicate> list = new ArrayList<>();
                    if (!khjc.equals("")) {
                        list.add(criteriaBuilder.like(root.get("khjc").as(String.class), "%" + khjc + "%"));
                    }
                    if (!khzjm.equals("")) {
                        list.add(criteriaBuilder.like(root.get("khzjm").as(String.class), "%" + khzjm + "%"));
                    }
                    if (!xlmc.equals("")) {
                        list.add(criteriaBuilder.like(root.get("xlmc").as(String.class), "%" + xlmc + "%"));
                    }
                    if (!xlzjm.equals("")) {
                        list.add(criteriaBuilder.like(root.get("xlzjm").as(String.class), "%" + xlzjm + "%"));
                    }
                    if (!qymc.equals("")) {
                        list.add(criteriaBuilder.like(root.get("qymc").as(String.class), "%" + qymc + "%"));
                    }
                    if (!qyzjm.equals("")) {
                        list.add(criteriaBuilder.like(root.get("qyzjm").as(String.class), "%" + qyzjm + "%"));
                    }
                    if (!ddh.equals("")) {
                        list.add(criteriaBuilder.like(root.get("ddh").as(String.class), "%" + ddh + "%"));
                    }
                    if (!ddzt.equals("")) {
                        list.add(criteriaBuilder.like(root.get("ddzt").as(String.class), "%" + ddzt + "%"));
                    }
                    if (!qsrq.equals("")) {
                        list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("ddrq").as(String.class), qsrq));
                    }
                    if (!jsrq.equals("")) {
                        list.add(criteriaBuilder.lessThanOrEqualTo(root.get("ddrq").as(String.class), jsrq));
                    }
                    if (!xq.equals("")) {
                        list.add(criteriaBuilder.equal(root.get("xingqi").as(String.class), xq));
                    }
                    if (!ddlx.equals("")) {
                        list.add(criteriaBuilder.equal(root.get("ddlx").as(String.class), ddlx));
                    }
                    list.add(criteriaBuilder.equal(root.get("sfcz").as(Boolean.class), true));
                    Predicate[] p = new Predicate[list.size()];
                    criteriaQuery.where(criteriaBuilder.and(list.toArray(p)));
                    criteriaQuery.orderBy(criteriaBuilder.desc(root.get("ddh")), criteriaBuilder.desc(root.get("qymc")));
                    return criteriaQuery.getRestriction();
                }
            };
        //分页信息
        Pageable pageable = new PageRequest(Integer.valueOf(pageNum)-1,Integer.valueOf(pageSize)); //页码：前端从1开始，jpa从0开始，做个转换
        Page<OrderMgmt> result = orderMapper.findAll(specification, pageable); //查询
        List<OrderMgmt> OrderMgmts = result.getContent();//获取Content
        String total =String.valueOf(result.getTotalElements());
        return ReturnInfo.info5(total,OrderMgmts,0,"");
    }

    //查询订单信息列表
    @RequiresPermissions("211")
    @RequestMapping(value = "order/road",method = RequestMethod.GET)
    public ReturnInfo getRoadListInOrder(){
        List<String> rodlist = orderMapper.findRoadInOrder();
        return ReturnInfo.info2(rodlist);
    }





    //查询订单信息

    @RequiresPermissions("211")
    @RequestMapping(value = "order/{ddid}",method = RequestMethod.GET)
    public OrderMgmt getOrderInfo(@PathVariable String ddid){
        return orderMapper.findByDdid(ddid);
    }

    //生成订单
    @MonitorRequest
    @RequiresPermissions("212")
    @RequestMapping(value = "order/{ddrq}",method = RequestMethod.POST)
    public ReturnInfo creatOrder(@PathVariable String ddrq){
        String b;
        if(!orderMapper.findByDdrqAndSfscdd(ddrq,true).toString().equals("[]")){
            b = "该天订单已生成！";
        }else {

            String week = GlobalParam.getWeek(ddrq);
            if(week.equals("星期格式错误！")){
                return ReturnInfo.info1(week);
            }
//            String ddh = ddrq.replaceAll("-","");
//            List<RoadView> result = roadVMapper.findBySfcz(true);
            List<RoadView> result = roadVMapper.findAll((Root<RoadView> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder)->{
                List<Predicate> list = new ArrayList<>();
                switch (week){
                    case "星期一":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhouyi").as(Boolean.class), true));
                        break;
                    case "星期二":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhouer").as(Boolean.class), true));
                        break;
                    case "星期三":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhousan").as(Boolean.class), true));
                        break;
                    case "星期四":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhousi").as(Boolean.class), true));
                        break;
                    case "星期五":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhouwu").as(Boolean.class), true));
                        break;
                    case "星期六":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhouliu").as(Boolean.class), true));
                        break;
                    case "星期日":
                        list.add(criteriaBuilder.equal(root.get("yxzqzhouri").as(Boolean.class), true));
                        break;
                    default:
                        break;
                }
                list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("xlyxqz").as(String.class), ddrq));
                list.add(criteriaBuilder.lessThanOrEqualTo(root.get("xlyxqq").as(String.class), ddrq));//生成线路有效期内的订单

                list.add(criteriaBuilder.equal(root.get("sfcz").as(Boolean.class), true));
                Predicate[] p = new Predicate[list.size()];
                criteriaQuery.where(criteriaBuilder.and(list.toArray(p)));
                criteriaQuery.orderBy(criteriaBuilder.desc(root.get("lasttime")));
                return criteriaQuery.getRestriction();
            });
            String ydj="";

            List<OilPrice>oilPrices = oilPriceMapper.findForOrder();
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            for(OilPrice oilPrice:oilPrices){
                try {
                    if(dateFormat.parse(oilPrice.getYdjqsrq()).getTime()<=dateFormat.parse(ddrq).getTime()){
                        ydj = oilPrice.getXydj();
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            for(RoadView roadView : result){
                OrderMgmt orderMgmt = new OrderMgmt(roadView);
                if(!ydj.equals("")){
                    orderMgmt.setYdj(ydj);
                }
                orderMgmt.setDdrq(ddrq);
                orderMgmt.setXingqi(week);
                String ddh = ddrq.replaceAll("-","");
                long i = orderMapper.countByDdrq(ddrq);
                orderMgmt.setDdh(ddh+GlobalParam.getDdh(i));
                orderMapper.save(orderMgmt);
            }
//            for (RoadView roadView : result) {
//                CycleInfo cycleInfo = null;
//                switch (week){
//                    case "星期日":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周日",ddrq);
//                        break;
//                    case "星期一":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周一",ddrq);
//                        break;
//                    case "星期二":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周二",ddrq);
//                        break;
//                    case "星期三":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周三",ddrq);
//                        break;
//                    case "星期四":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周四",ddrq);
//                        break;
//                    case "星期五":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周五",ddrq);
//                        break;
//                    case "星期六":
//                        cycleInfo = cycleMapper.findTop1ByXlidAndYxzqAndYxrqLessThanEqualOrderByTjsjDesc(roadView.getXlid(),"周六",ddrq);
//                        break;
//                    default:
//                        break;
//                }
//                if(cycleInfo!=null&&cycleInfo.getSfyx()){
//                    OrderMgmt orderMgmt = new OrderMgmt(roadView);
//                    orderMgmt.setDdrq(ddrq);
//                    long i = orderMapper.countByDdrq(ddrq);
//                    orderMgmt.setDdh(ddh + GlobalParam.getDdh(i));
//                    orderMapper.save(orderMgmt);
//                }
//            }
            b = "订单生成成功！";
            logger.info("日期"+ddrq+" "+week+"  订单已生成！");
        }
        return ReturnInfo.info1(b);
    }

    //生成零散订单/加车
    @MonitorRequest
    @RequiresPermissions(value = {"213","214"},logical = Logical.OR)
    @RequestMapping(value = "order",method = RequestMethod.POST)
    public List<Map<String,Object>> saveOrder(@RequestBody OrderMgmt orderMgmt){
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();
        if(orderMapper.findByDdidAndSfcz(orderMgmt.getDdid(),true)==null){//生成零散订单
            if(cstmrMapper.findByKhidAndSfcz(orderMgmt.getKhid(),true)==null){
                map.put("khid","1");
            }
            if(areaMapper.findByQyidAndSfcz(orderMgmt.getQyid(),true)==null){
                map.put("qyid","1");
            }
//            if(roadMapper.findByXlidAndSfcz(orderMgmt.getXlid(),true)==null){
//                map.put("xlid","1");
//            }
//            if(!orderMgmt.getHwsl().equals("")&&!checkInteger(orderMgmt.getHwsl())){
//                map.put("hwsl","0");
//            }（客户说要在新增零散订单时去掉货物数量这一栏）
            if(!orderMgmt.getYunfei().equals("")&&!checknumber(orderMgmt.getYunfei())){
                map.put("yunfei","0");
            }
            if(!orderMgmt.getGls().equals("")&&!checknumber(orderMgmt.getGls())){
                map.put("gls","0");
            }
            if(!orderMgmt.getYdj().equals("")&&!checknumber(orderMgmt.getYdj())){
                map.put("ydj","0");
            }
            list.add(map);
            if(map.isEmpty()){
                String ddrq = orderMgmt.getDdrq();
                orderMgmt.setXingqi(GlobalParam.getWeek(ddrq));
                String ddh = ddrq.replaceAll("-","");
                long i = orderMapper.countByDdrq(ddrq);
                orderMgmt.setDdh(ddh+GlobalParam.getDdh(i));
                CstmrInfo cstmrInfo = cstmrMapper.findByKhid(orderMgmt.getKhid());
                orderMgmt.setKhjc(cstmrInfo.getKhjc());
                orderMgmt.setKhzjm(cstmrInfo.getKhzjm());
                AreaInfo areaInfo = areaMapper.findByQyidAndSfcz(orderMgmt.getQyid(), true);
                orderMgmt.setQymc(areaInfo.getQymc());
                orderMgmt.setZjm(areaInfo.getZjm());
//                RoadInfo roadInfo = roadMapper.findByXlid(orderMgmt.getXlid());
//                orderMgmt.setXlmc(roadInfo.getXlmc());
//                orderMgmt.setXlzjm(roadInfo.getXlzjm());
                orderMgmt.setDdlx("零散订单");
                orderMgmt.setSfcz(true);
                orderMgmt.setSfscdd(false);
                orderMgmt.setDdid(null);
                orderMapper.save(orderMgmt);
                logger.info("生成零散订单"+orderMgmt.toString());
            }
        }else {
            if(orderMgmt.getDdid()==null||orderMgmt.getDdid().equals("")){
                map.put("ddid", "0");
            }
            if(!orderMgmt.getHwsl().equals("")&&!checkInteger(orderMgmt.getHwsl())){
                map.put("hwsl","0");
            }
            if(!orderMgmt.getYunfei().equals("")&&!checknumber(orderMgmt.getYunfei())){
                map.put("yunfei","0");
            }
            if(!orderMgmt.getGls().equals("")&&!checknumber(orderMgmt.getGls())){
                map.put("gls","0");
            }
            if(!orderMgmt.getYdj().equals("")&&!checknumber(orderMgmt.getYdj())){
                map.put("ydj","0");
            }
            list.add(map);
            if(map.isEmpty()){
                String ddrq = orderMgmt.getDdrq();
//                orderMgmt.setDdrq(ddrq);
                String ddh = ddrq.replaceAll("-","");
                long i = orderMapper.countByDdrq(ddrq);
                orderMgmt.setDdh(ddh+GlobalParam.getDdh(i));
                orderMgmt.setDdlx("加车单");
                orderMgmt.setSfcz(true);
                orderMgmt.setSfscdd(false);
                orderMgmt.setDdid(null);
                orderMapper.save(orderMgmt);
                logger.info("生成加车单"+orderMgmt.toString());
            }
        }
        return list;
    }

    //编辑订单
    @MonitorRequest
    @RequiresPermissions("216")
    @RequestMapping(value = "order",method = RequestMethod.PUT)
    public List<Map<String,Object>> updateOrder(@RequestBody OrderMgmt orderMgmt){
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();
        if(orderMgmt.getDdid()==null||orderMgmt.getDdid().equals("")){
            map.put("ddid", "0");
        }
        if(!orderMgmt.getHwsl().equals("")&&!checkInteger(orderMgmt.getHwsl())){
            map.put("hwsl","0");
        }
        if(!orderMgmt.getYunfei().equals("")&&!checknumber(orderMgmt.getYunfei())){
            map.put("yunfei","0");
        }
        if(!orderMgmt.getGls().equals("")&&!checknumber(orderMgmt.getGls())){
            map.put("gls","0");
        }
        if(!orderMgmt.getYdj().equals("")&&!checknumber(orderMgmt.getYdj())){
            map.put("ydj","0");
        }
        list.add(map);
        if(map.isEmpty()){
            orderMapper.UpdateByDdid(orderMgmt.getDdid(),orderMgmt.getHuowu(),orderMgmt.getHwsl(),orderMgmt.getYdj(),orderMgmt.getYunfei(),orderMgmt.getGls());
            logger.info("编辑订单"+orderMgmt.toString());
        }
        return list;
    }

    //发布订单
    @MonitorRequest(type="order",description = "订单管理 发布订单")
    @RequiresPermissions("215")
    @RequestMapping(value = "order/{ddid}",method = RequestMethod.PUT)
    public ReturnInfo issueOrder(@PathVariable String ddid){
        String b;
        if(orderMapper.findByDdid(ddid)==null){
            b = "订单不存在！";
        }else {
            OrderMgmt orderMgmt = orderMapper.findByDdid(ddid);
            WaybillMgmt waybillMgmt = new WaybillMgmt(orderMgmt);
            try{
                orderMapper.IssueByDdid(ddid);
                waybillMgmt.setFcrq(orderMgmt.getDdrq());
                RoadInfo roadInfo = roadMapper.findByXlmcAndSfcz(waybillMgmt.getXlmc(), true);
                if (roadInfo!=null&&roadInfo.getXllx() != null && roadInfo.getXllx().equals("单开")) {
                    waybillMgmt.setLeixing("带货");
                }

                waybillMapper.save(waybillMgmt);
                b = "订单发布成功！";
                logger.info("发布订单成功"+ddid);
            }catch (NullPointerException e){
                b = "订单发布失败！";
                logger.info("发布订单失败"+ddid);
            }
        }
        return ReturnInfo.info1(b);
    }

    //批量发布订单
    @MonitorRequest
    @RequiresPermissions("215")
    @RequestMapping(value = "order/batch",method = RequestMethod.PUT)
    public ReturnInfo batchIssueOrder(@RequestBody OrderMgmt orderMgmt){
        List<String> failList = new ArrayList<>();
        for(String ddid : orderMgmt.getDdidList()){
            if(orderMapper.findByDdid(ddid)==null){
                failList.add(ddid);
            }else{
                OrderMgmt orderM = orderMapper.findByDdid(ddid);
                WaybillMgmt waybillMgmt = new WaybillMgmt(orderM);
                try{
                    RoadInfo roadInfo =  roadMapper.findByXlmcAndSfcz(waybillMgmt.getXlmc(),true);
                    if(roadInfo!=null&&roadInfo.getXllx()!=null&&roadInfo.getXllx().equals("单开")){
                        waybillMgmt.setLeixing("带货");
                    }
                    waybillMapper.save(waybillMgmt);
                    waybillMgmt.setFcrq(orderM.getDdrq());
                    orderMapper.IssueByDdid(ddid);
                    logger.info("发布订单成功"+ddid);
                }catch (NullPointerException e){
                    failList.add(ddid);
                    logger.info("发布订单失败"+ddid);
                }
            }
        }
        return ReturnInfo.info4("成功",failList);
    }

    //删除订单
    @MonitorRequest
    @RequiresPermissions("217")
    @RequestMapping(value = "order/{ddid}",method = RequestMethod.DELETE)
    public ReturnInfo deleteOrder(@PathVariable String ddid){
        String b;
        if(orderMapper.findByDdid(ddid)==null){
            b = "删除失败！";
        }else {
            orderMapper.DeleteByDdid(ddid);
            b = "删除成功！";
            logger.info("删除订单成功"+ddid);
        }
        return ReturnInfo.info1(b);
    }

    //批量删除订单
    @RequiresPermissions("217")
    @RequestMapping(value = "order/batch",method = RequestMethod.DELETE)
    public ReturnInfo batchDeleteOrder(@RequestBody OrderMgmt orderMgmt){
        List<String> failList = new ArrayList<>();
        for (String ddid : orderMgmt.getDdidList()){
            if(orderMapper.findByDdid(ddid)==null){
                failList.add(ddid);
            }else {
                orderMapper.DeleteByDdid(ddid);
                logger.info("删除订单成功"+ddid);
            }
        }
        return ReturnInfo.info4("成功",failList);
    }

    //查询运单数量
    @RequestMapping(value = "orderNum1", method = RequestMethod.GET)
    public ReturnInfo getOrderNum1(){
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map1 = new HashMap<>();
        Map<String,Object>  map2 = new HashMap<>();
        Map<String,Object>  map3 = new HashMap<>();
        Integer orderYwc = orderMapper.findDdywc();
        Integer orderYfb = orderMapper.findDdyfb();
        Integer orderDfb = orderMapper.findDddfb();
        if(orderYwc>0){
            map1.put("department","已完成");
            map1.put("num",orderYwc);
            list.add(map1);
        }
        if(orderYfb>0){
            map2.put("department","已发布");
            map2.put("num",orderYfb);
            list.add(map2);
        }
        if(orderDfb>0){
            map3.put("department","待发布");
            map3.put("num",orderDfb);
            list.add(map3);
        }

        return ReturnInfo.info2(list);
    }

    //查询数量
    @RequestMapping(value = "orderNum2", method = RequestMethod.GET)
    public ReturnInfo getOrderNum2() {
        List<Map<String, Object>> dingdan = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        Map<String, Object> map4 = new HashMap<>();
        Map<String, Object> map5 = new HashMap<>();
        Map<String, Object> map6 = new HashMap<>();
        Map<String, Object> map7 = new HashMap<>();
        Map<String, Object> map8 = new HashMap<>();
        Map<String, Object> map9 = new HashMap<>();
        Map<String, Object> map10 = new HashMap<>();
        Map<String, Object> map11 = new HashMap<>();
        Map<String, Object> map12 = new HashMap<>();
        Map<String, Object> map13 = new HashMap<>();
        Map<String, Object> map14 = new HashMap<>();
        Map<String, Object> map15 = new HashMap<>();
        Map<String, Object> map16 = new HashMap<>();
        Map<String, Object> map17 = new HashMap<>();
        Map<String, Object> map18 = new HashMap<>();
        Map<String, Object> map19 = new HashMap<>();
        Map<String, Object> map20 = new HashMap<>();
        Map<String, Object> map21 = new HashMap<>();
        Map<String, Object> map22 = new HashMap<>();
        Map<String, Object> map23 = new HashMap<>();
        Map<String, Object> map24 = new HashMap<>();
        Map<String, Object> map25 = new HashMap<>();
        Map<String, Object> map26 = new HashMap<>();
        Map<String, Object> map27 = new HashMap<>();
        Map<String, Object> map28 = new HashMap<>();
        Map<String, Object> map29 = new HashMap<>();
        Map<String, Object> map30 = new HashMap<>();
        Map<String, Object> map31 = new HashMap<>();


        map1.put("AREA", GlobalParam.yyMMdd(-30));
        map1.put("LANDNUM", orderMapper.findDd30dl());
        map2.put("AREA", GlobalParam.yyMMdd(-29));
        map2.put("LANDNUM", orderMapper.findDd29dl());
        map3.put("AREA", GlobalParam.yyMMdd(-28));
        map3.put("LANDNUM", orderMapper.findDd28dl());
        map4.put("AREA", GlobalParam.yyMMdd(-27));
        map4.put("LANDNUM", orderMapper.findDd27dl());
        map5.put("AREA", GlobalParam.yyMMdd(-26));
        map5.put("LANDNUM", orderMapper.findDd26dl());
        map6.put("AREA", GlobalParam.yyMMdd(-25));
        map6.put("LANDNUM", orderMapper.findDd25dl());
        map7.put("AREA", GlobalParam.yyMMdd(-24));
        map7.put("LANDNUM", orderMapper.findDd24dl());
        map8.put("AREA", GlobalParam.yyMMdd(-23));
        map8.put("LANDNUM", orderMapper.findDd23dl());
        map9.put("AREA", GlobalParam.yyMMdd(-22));
        map9.put("LANDNUM", orderMapper.findDd22dl());
        map10.put("AREA", GlobalParam.yyMMdd(-21));
        map10.put("LANDNUM", orderMapper.findDd21dl());
        map11.put("AREA", GlobalParam.yyMMdd(-20));
        map11.put("LANDNUM", orderMapper.findDd20dl());
        map12.put("AREA", GlobalParam.yyMMdd(-19));
        map12.put("LANDNUM", orderMapper.findDd19dl());
        map13.put("AREA", GlobalParam.yyMMdd(-18));
        map13.put("LANDNUM", orderMapper.findDd18dl());
        map14.put("AREA", GlobalParam.yyMMdd(-17));
        map14.put("LANDNUM", orderMapper.findDd17dl());
        map15.put("AREA", GlobalParam.yyMMdd(-16));
        map15.put("LANDNUM", orderMapper.findDd16dl());
        map16.put("AREA", GlobalParam.yyMMdd(-15));
        map16.put("LANDNUM", orderMapper.findDd15dl());
        map17.put("AREA", GlobalParam.yyMMdd(-14));
        map17.put("LANDNUM", orderMapper.findDd14dl());
        map18.put("AREA", GlobalParam.yyMMdd(-13));
        map18.put("LANDNUM", orderMapper.findDd13dl());
        map19.put("AREA", GlobalParam.yyMMdd(-12));
        map19.put("LANDNUM", orderMapper.findDd12dl());
        map20.put("AREA", GlobalParam.yyMMdd(-11));
        map20.put("LANDNUM", orderMapper.findDd11dl());
        map21.put("AREA", GlobalParam.yyMMdd(-10));
        map21.put("LANDNUM", orderMapper.findDd10dl());
        map22.put("AREA", GlobalParam.yyMMdd(-9));
        map22.put("LANDNUM", orderMapper.findDd9dl());
        map23.put("AREA", GlobalParam.yyMMdd(-8));
        map23.put("LANDNUM", orderMapper.findDd8dl());
        map24.put("AREA", GlobalParam.yyMMdd(-7));
        map24.put("LANDNUM", orderMapper.findDd7dl());
        map25.put("AREA", GlobalParam.yyMMdd(-6));
        map25.put("LANDNUM", orderMapper.findDd30dl());
        map26.put("AREA", GlobalParam.yyMMdd(-5));
        map26.put("LANDNUM", orderMapper.findDd5dl());
        map27.put("AREA", GlobalParam.yyMMdd(-4));
        map27.put("LANDNUM", orderMapper.findDd4dl());
        map28.put("AREA", GlobalParam.yyMMdd(-3));
        map28.put("LANDNUM", orderMapper.findDd3dl());
        map29.put("AREA", GlobalParam.yyMMdd(-2));
        map29.put("LANDNUM", orderMapper.findDd2dl());
        map30.put("AREA", GlobalParam.yyMMdd(-1));
        map30.put("LANDNUM", orderMapper.findDd1dl());
        map31.put("AREA", GlobalParam.yyMMdd(0));
        map31.put("LANDNUM", orderMapper.findDd0dl());

        dingdan.add(map1);
        dingdan.add(map2);
        dingdan.add(map3);
        dingdan.add(map4);
        dingdan.add(map5);
        dingdan.add(map6);
        dingdan.add(map7);
        dingdan.add(map8);
        dingdan.add(map9);
        dingdan.add(map10);
        dingdan.add(map11);
        dingdan.add(map12);
        dingdan.add(map13);
        dingdan.add(map14);
        dingdan.add(map15);
        dingdan.add(map16);
        dingdan.add(map17);
        dingdan.add(map18);
        dingdan.add(map19);
        dingdan.add(map20);
        dingdan.add(map21);
        dingdan.add(map22);
        dingdan.add(map23);
        dingdan.add(map24);
        dingdan.add(map25);
        dingdan.add(map26);
        dingdan.add(map27);
        dingdan.add(map28);
        dingdan.add(map29);
        dingdan.add(map30);
        dingdan.add(map31);

        Map<String, Object> lists = new HashMap<>();
        lists.put("dingdan", dingdan);
        return ReturnInfo.info2(lists);
    }

    //检查整数
    private Boolean checkInteger(String integer){
        Boolean b = false;
        if(integer.matches("^[1-9][0-9]{0,14}$")){
            b = true;
        }
        return b;
    }

    //检查数
    private Boolean checknumber(String number){
        Boolean b = false;
        if(number.matches("^[0-9.]{0,14}$")){
            b = true;
        }
        return b;
    }
}